"""
Case Type   : USTORE
Case Name   : 验证参数ustore_attr(index_trace_level)的异常值
Create At   : 2025/3/25
Owner       : wan005
Description :
    1.修改index_trace_level的值为2,'abc','abc_123$'
Expect      :
    1.修改失败
History     :
"""
import os
import unittest
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Common import Common
from testcase.utils.Logger import Logger
from testcase.utils.Constant import Constant


class Security(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f'---{os.path.basename(__file__)} start---')
        self.sh_primy = CommonSH('PrimaryDbUser')
        self.constant = Constant()
        self.common = Common()
        self.default_params = \
            'ustore_verify_level=FAST;ustore_verify_module=UPAGE:UBTREE'

    def test_ustore(self):
        text = '----step1:修改参数值为2,abc,abc_123$;expect:失败----'
        self.logger.info(text)
        self.sh_primy.execute_gsguc('reload', self.constant.GSGUC_SUCCESS_MSG,
                                    "ustore_attr='ustore_verify_level=FAST;"
                                    "index_trace_level=2'")
        re1_1 = self.common.show_param('ustore_attr')
        self.assertEqual(self.default_params, re1_1, text + '执行失败')

        self.sh_primy.execute_gsguc('reload', self.constant.GSGUC_SUCCESS_MSG,
                                    "ustore_attr='ustore_verify_level=FAST;"
                                    "index_trace_level=abc'")
        res1_2 = self.common.show_param('ustore_attr')
        self.assertEqual(self.default_params, res1_2, text + '执行失败')

        self.sh_primy.execute_gsguc('reload', self.constant.GSGUC_SUCCESS_MSG,
                                    "ustore_attr='ustore_verify_level=FAST;"
                                    "index_trace_level=abc_123$'")
        res1_3 = self.common.show_param('ustore_attr')
        self.assertEqual(self.default_params, res1_3, text + '执行失败')

    def tearDown(self):
        text = '-----step1:清理环境，恢复配置;expect:成功-----'
        self.logger.info(text)
        self.sh_primy.execute_gsguc('reload', self.constant.GSGUC_SUCCESS_MSG,
                                    f"ustore_attr='{self.default_params}'")
        res_show = self.common.show_param('ustore_attr')
        self.assertEqual(self.default_params, res_show, text + '执行失败')
        self.logger.info(f'---{os.path.basename(__file__)} end---')
